package com.nbjtjc.safe.service.safe;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.safe.SafeDangerChemicalMapper;
import com.nbjtjc.safe.model.safe.SafeDangerChemical;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class SafeDangerChemicalServiceImpl {

    @Autowired
    private SafeDangerChemicalMapper chemicalMapper;

    public Result find(SafeDangerChemical chemical){
        Result result=new Result();
        PageHelper.startPage(chemical.getPageCurrent(),chemical.getPageSize());
        List<SafeDangerChemical> chemicalList= chemicalMapper.select(chemical);
        result.setData(new PageInfo<>(chemicalList));
        return result;
    }

    @Transactional
    public Result add(SafeDangerChemical chemical){
        Result result=new Result();
        chemicalMapper.insertSelective(chemical);
        result.setData(chemical);
        return result;
    }

    public Result update(SafeDangerChemical chemical){
        Result result=new Result();
        chemicalMapper.updateByPrimaryKeySelective(chemical);
        result.setData(chemical);
        return result;
    }

    public Result delete(SafeDangerChemical chemical){
        Result result=new Result();
        chemicalMapper.delete(chemical);
        return result;
    }

}
